package com.yami.repository

import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional
import org.springframework.beans.factory.annotation.Autowired
import org.hibernate.{Session, SessionFactory}
import java.util.{List => JList }
import com.yami.domain.Artist

/**
 *
 * @ author caibosi
 * @ created 2014-08-07
 *
 */

trait ArtistDb{
  def findAll: JList[Artist]
  def save(artist:Artist): Long
}

@Repository
class ArtistRepository extends ArtistDb{

  @Autowired
  var sessionFactory: SessionFactory = null

  private def currentSession = sessionFactory.getCurrentSession

  @Transactional
  def save(artist:Artist): Long = currentSession.save(artist).asInstanceOf[Long]

  @Transactional
  def findAll: JList[Artist] = currentSession.createCriteria(classOf[Artist]).list().asInstanceOf[JList[Artist]]

}
